package com.qiaoyanqing.ximalaya.util;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;

import com.squareup.picasso.Transformation;

/**
 * Created by 佳男 on 2016/12/8.
 */

public class CircleTransform implements Transformation{
    @Override
    public Bitmap transform(Bitmap source) {
        Bitmap bitmap=Bitmap.createBitmap(source.getWidth(),source.getHeight(), Bitmap.Config.ARGB_8888);
        Paint paint=new Paint();
        paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP,
                Shader.TileMode.CLAMP));
        new Canvas(bitmap).drawCircle(source.getWidth()/2,source.getHeight()/2,
                source.getWidth()/2>source.getHeight()/2?source.getHeight()/2:source.getWidth()/2,paint);
        source.recycle();
        return bitmap;
    }

    @Override
    public String key() {
        return "circle";
    }
}
